package com.skywolf.chem.pageconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skywolf.chem.article.entity.CollectionInfo;
import com.skywolf.chem.manager.entity.ColumnQueryParam;
import com.skywolf.chem.pageconfig.entity.ColumnInfo;
import com.skywolf.chem.pageconfig.mapper.ColumnInfoMapper;
import com.skywolf.chem.pageconfig.service.IColumnInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 栏目表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-06-09
 */
@Service
public class ColumnInfoServiceImpl extends ServiceImpl<ColumnInfoMapper, ColumnInfo> implements IColumnInfoService {

    @Autowired
    ColumnInfoMapper columnInfoMapper;

    @Override
    public IPage<ColumnInfo> ColumnPageList(ColumnQueryParam queryParam) {
        QueryWrapper<ColumnInfo> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(queryParam.getPositionName())){
            queryWrapper.eq("position_name",queryParam.getPositionName());
        }
        if(StringUtils.isNotBlank(queryParam.getColName())){
            queryWrapper.like("col_name", queryParam.getColName());
        }
        queryWrapper.orderByDesc("col_sort").orderByDesc("created_time");
        return this.page(queryParam.page(), queryWrapper);
    }

    @Override
    public ColumnInfo getCity(String name) {
        name = name.replaceAll("市","");
        return columnInfoMapper.getCity(name);
    }

    @Override
    public List<ColumnInfo> getOtherCity(String name) {
        name = name.replaceAll("市","");
        ColumnInfo columnInfo = columnInfoMapper.getCity(name);
        List<ColumnInfo> columnInfos = columnInfoMapper.getOtherCity(name);
        if(columnInfo!=null){
            if(columnInfos!=null && columnInfos.size()>0){
                columnInfos.add(0,columnInfo);
                return columnInfos;
            }else{
                List<ColumnInfo> list = new ArrayList<ColumnInfo>();
                list.add(columnInfo);
                return list;
            }
        }
        return columnInfos;
    }

    @Override
    public List<ColumnInfo> getAllCity() {
        QueryWrapper<ColumnInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("city",1);
        return this.list(queryWrapper);
    }
}
